// user.js
var api = require('../../api.js');
var app = getApp();
const date = new Date()
const years = []
const months = []
for (let i = 2008; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  months.push(i)
}

Page({
  /**
   * 页面的初始数据
   */
  data: {
    years: years,
    year: date.getFullYear(),
    months: months,
    month: date.getMonth() + 1,
    value: [9999, date.getMonth()],
    bill3_list: null,
    is_choose: false,
    newYear: date.getFullYear(),
    newMonth: date.getMonth() + 1,
    total_money: 0.00,
    rebate_money: 0.00
  },
  bindChange: function(e) {
    const val = e.detail.value
    this.setData({
      newYear: this.data.years[val[0]],
      newMonth: this.data.months[val[1]],
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // var t = getChooseTime();
    var page = this;
    var year = page.data.year;
    var month = page.data.month;
    if (month < 10) {
      var t = year + '-0' + month;
    } else {
      var t = year + '-' + month;
    }
    page.getBill_list(1, t)
  },
  // 获取 时间参数
  // getChooseTime() {
  //     var page = this;
  //     var year = page.date.year;
  //     var month = page.data.month;
  //     if (month < 10) {
  //         var t = year + '-0' + month;
  //     } else {
  //         var t = year + '-' + month;
  //     }
  //     return t;
  // },
  // 筛选时间
  slide_choose() {
    var page = this;
    page.setData({
      is_choose: !page.data.is_choose
    })
  },
  // 取消   筛选时间
  removeChoose() {
    var page = this;
    page.setData({
      is_choose: false,
    })
    page.getBill_list(1);
  },
  //确定
  addChoose() {
    var page = this;
    
    page.setData({
      is_choose: false,
      year: page.data.newYear,
      month: page.data.newMonth,
      value: [9999, page.data.newMonth-1],
    })
    if (page.data.newYear && page.data.newMonth) {

      var year = page.data.year;
      var month = page.data.month;
      if (month < 10) {
        var t = year + '-0' + month;
      } else {
        var t = year + '-' + month;
      }
      page.getBill_list(1, t);
    }
  },
  // 获取提现账单
  getBill_list(p, t) {
    var page = this;
    app.request({
      url: api.user.withdrawalsList,
      data: {
        // uid: wx.getStorageSync("user_info").user_id,
        token: app.globalData.token,
        page: p,
        searchTime: t
      },
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        if (res.code == 1) {
          page.setData({
            bill3_list: res.data.list,
            total_money: res.data.total_money,
            rebate_money: res.data.rebate_money,
          })
        } else {
          page.setData({
            bill3_list: [],
            total_money: 0.00,
            rebate_money: 0.00,
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  getOrderCountData: function() {

  },
  onPullDownRefresh: function() {

  }
});